interface SquareConfig {
    color?: string;
    width?: number;
  }
  

//   {color: string; area: number} 为返回值类型
  function createSquare(config: SquareConfig): {color: string; area: number} {
    let newSquare = {color: "white", area: 100};
    if (config.color) {
      newSquare.color = config.color;
    }
    if (config.width) {
      newSquare.area = config.width * config.width;
    }
    return newSquare;
  }
  
  let mySquare = createSquare({color: "black"});


//   只读属性
  interface Point {
    readonly x: number;
    readonly y: number;
}
let p1: Point = { x: 10, y: 20 };
// p1.x = 5; // error! readonly表示为只读


// 函数类型

let mySearch = function(src: string, sub: string): boolean {
  let result = src.search(sub);
  return result > -1;
}